package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.apis.AdChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    AdChannelService adChannelService;

    @Override
    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        ResponseResult byNameAndPage = adChannelService.findByNameAndPage(dto);
        return byNameAndPage;
    }

    @Override
    @PostMapping("/save")
    public ResponseResult insertAdChannel(@RequestBody AdChannel channel) {
        ResponseResult responseResult = adChannelService.insertAdChannel(channel);
        return responseResult;
    }

    @Override
    @PostMapping("/update")
    public ResponseResult updateAdChannel(@RequestBody AdChannel channel) {
        ResponseResult responseResult = adChannelService.updateAdChannel(channel);
        return responseResult;
    }

    @Override
    @GetMapping("/delete/{id}")
    public ResponseResult deleteAdChannel(@PathVariable("id") Integer id) {
        ResponseResult responseResult = adChannelService.deleteAdChannel(id);
        return responseResult;
    }
}
